package com.example.feitou.backpressed;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private long lastPressdeTime = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public void onBackPressed() {
        long currentPressedTime = System.currentTimeMillis();
        if(currentPressedTime - lastPressdeTime>2000){
            lastPressdeTime = currentPressedTime;
            Toast.makeText(MainActivity.this,"再按一次退出",Toast.LENGTH_SHORT).show();
        }else {
            super.onBackPressed();
        }
    }
}
